<template>
  <el-menu
    active-text-color="#4169e1"
    background-color="#333"
    class="el-menu-vertical-demo"
    text-color="#fff"
    :collapse="$store.state.HomeModule.navBool"
    router
    @open="handleOpen"
    @close="handleClose"
  >
    <template v-for="v in router.options.routes[1].children" :v.path>
      <!-- 带下拉列表 -->
      <el-sub-menu :index="v.path" v-if="v.children">
        <template #title>
          <el-icon>
            <component :is="v.meta.icon"></component>
          </el-icon>
          <span>{{ v.meta.title }}</span>
        </template>
        <el-menu-item-group v-for="k in v.children" :key="k.path">
          <el-menu-item :index="k.path">{{ k.meta.title }}</el-menu-item>
          <!-- <el-menu-item index="1-2">item one</el-menu-item> -->
        </el-menu-item-group>
      </el-sub-menu>
      <!-- 不带下拉列表 -->

      <el-menu-item :index="v.path" v-else>
        <el-icon>
          <component :is="v.meta.icon"></component>
        </el-icon>
        <span>{{ v.meta.title }}</span>
      </el-menu-item>
    </template>
  </el-menu>
</template>
    
<script setup lang='ts'>
import { onMounted } from "vue";
import { useRouter } from "vue-router";

const handleOpen = (key: string, keyPath: string[]) => {
  console.log(key, keyPath);
};
const handleClose = (key: string, keyPath: string[]) => {
  console.log(key, keyPath);
};
let router = useRouter();
onMounted(() => {
  console.log("获取路由规则", router.options.routes[1].children);
});
</script>
    
<style lang="scss" scoped>
.el-menu-vertical-demo:not(.el-menu--collapse) {
  width: 200px;
  min-height: 400px;
}
.el-menu-vertical-demo /deep/ .is-active {
  background: #00000014;
}
.el-menu-vertical-demo /deep/ aside {
  background-color: #333;
}
</style>